package com.pig4cloud.pigx.common.security.component;

import com.pig4cloud.pigx.common.security.constant.CacheConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.ClientRegistrationException;
import org.springframework.security.oauth2.provider.client.JdbcClientDetailsService;

import javax.sql.DataSource;

/**
 * @description:
 * @Author 兔子不吃窝边曹
 * @create 2022/7/29 15:56
 **/
@Slf4j
public class PigxJdbcClientDetailsServiceImpl extends JdbcClientDetailsService {

    public PigxJdbcClientDetailsServiceImpl(DataSource dataSource) {
        super(dataSource);
    }

    @Override
    @Cacheable(value = CacheConstants.CLIENT_DETAILS_KEY, key = "#clientId", unless = "#result == null")
    public ClientDetails loadClientByClientId(String clientId) throws ClientRegistrationException {
        try {
            ClientDetails clientDetails = super.loadClientByClientId(clientId);
            return clientDetails;
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }
}
